<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 修改密码
 * @author 		jaypha
 * @qq			168007694
 * @email		psufool@163.com
 * @home page	www.psufool.cn
 */
class Changepwd extends Admin_Controller{
	
	function __construct(){
		parent::__construct();
		$this->load->model('JayphaDB');
		if(is_null($this->adminCurrentTemplate) or empty($this->adminCurrentTemplate)){
			$this->adminCurrentTemplate = 'default';
		}
		$this->dbTablePrefix = $this->config->item('db_table_prefix');
	}
	
	function index(){
		if(!$this->noLoginErr()) return false;
		$data['adminCurrentTemplate'] = $this->adminCurrentTemplate;
		$data['pageTag'] = '修改密码';
		$data['currentSite'] = '';
		$data['perm'] = 'changepwd';
		$data['phpSelf'] = site_url('admin/changepwd');
		if($this->input->server('REQUEST_METHOD')=='POST'){
			$oldpwd = $this->input->post('oldpwd');
			$newpwd = $this->input->post('newpwd');
			$renewpwd = $this->input->post('renewpwd');
			if(strlen($oldpwd)==0){
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>220,
					'height'=>108,
					'title'=>'修改密码错误',
					'content'=>'<span class="red" style="line-height:22px;">对不起，请输入您的原密码！</span>',
					'url'=>'history.back();',
					'target'=>'',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'返回',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}
			if(strlen($newpwd)==0){
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>220,
					'height'=>108,
					'title'=>'修改密码错误',
					'content'=>'<span class="red" style="line-height:22px;">对不起，请输入您的新密码！</span>',
					'url'=>'history.back();',
					'target'=>'',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'返回',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}
			if(strlen($renewpwd)==0){
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>260,
					'height'=>108,
					'title'=>'修改密码错误',
					'content'=>'<span class="red" style="line-height:22px;">对不起，请再次输入您的新密码！</span>',
					'url'=>'history.back();',
					'target'=>'',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'返回',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}
			if($newpwd!=$renewpwd){
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>340,
					'height'=>108,
					'title'=>'修改密码错误',
					'content'=>'<span class="red" style="line-height:22px;">对不起，两次输入的新密码不相同，请重新输入！</span>',
					'url'=>'history.back();',
					'target'=>'',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'返回',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}
			$where = array(
					'id'=>$this->session->userdata('adminUserId'),
					'userPWD'=>strtoupper(md5($oldpwd)));
			if($this->JayphaDB->getDBCount($this->dbTablePrefix.'admin',$where)==0){
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>300,
					'height'=>108,
					'title'=>'修改密码错误',
					'content'=>'<span class="red" style="line-height:22px;">对不起，您的原密码不正确，请重新输入！</span>',
					'url'=>'history.back();',
					'target'=>'',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'返回',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}else{
				$updata = array('userPWD'=>strtoupper(md5($newpwd)));
				$where = array('id'=>$this->session->userdata('adminUserId'));
				$this->JayphaDB->updateDB($updata,$this->dbTablePrefix.'admin',$where);
				$data['errorScript'] = array('lhgdialog_alert_mess_top'=>array(
					'width'=>280,
					'height'=>108,
					'title'=>'密码修改成功',
					'content'=>'<span class="red" style="line-height:22px;">恭喜您，密码修改成功，请重新登陆！</span>',
					'url'=>site_url('admin/login/logout'),
					'target'=>'_top',
					'conver'=>true,
					'resize'=>false,
					'drag'=>true,
					'btns'=>true,
					'btnText'=>'确 定',
					'rightClose'=>false
				));
				$this->load->view("admin/$this->adminCurrentTemplate/error",$data);
				return false;
			}
		}
		$this->load->view("admin/$this->adminCurrentTemplate/changepwd",$data);
	}
}

/* End of file changepwd.php */
/* Location: ./application/controllers/admin/changepwd.php */